'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-11-09 15:09:14
'''
#
# @lc app=leetcode.cn id=594 lang=python3
#
# [594] 最长和谐子序列
#

# @lc code=start
from typing import List
class Solution:
    def findLHS(self, nums: List[int]) -> int:
        import collections

        store = {}
        for num in nums:
            if num not in store:
                store[num]=0
            store[num]+=1
        ans = 0
        for k, v in store.items():
            ans = max(ans, v+store[k-1]) if k-1 in store else ans
        return ans
            

# @lc code=end

